Skip to content

Conversation

Yunuuuu
Copy link
Contributor

@Yunuuuu Yunuuuu commented Aug 23, 2025

fix #6575

n <- vapply(
    split(mpg, ~cyl),
    function(d) length(unique(d$class)),
    integer(1L)
)

dplyr::mutate(mpg,
    width = length(unique(class)),
    median = length(unique(class)) / 2L,
    .by = cyl
) |>
    ggplot() +
    geom_boxplot(
        aes(median, hwy, group = median, width = width)
    ) +
    facet_wrap(vars(cyl), nrow = 1L, space = "free_x", scales = "free_x") +
    ggh4x::facetted_pos_scales(
        lapply(n, function(max) scale_x_continuous(limits = c(0, max)))
    )
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Respect width aes in geom_boxplot
1 participant